<?php

namespace App\Models\coupon;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class CmcPromotionCoupon extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'cmc_promotion_coupon';


    static public function getListGoodsCoupon($data,$memberId,$gid)
    {
        // 根据优惠券id、用户id、商品id进行关联查询
        return self::join('cmc_promotion_coupon_type','cmc_promotion_coupon.type','=','cmc_promotion_coupon_type.id')
            ->join('cmc_promotion_coupon_user','cmc_promotion_coupon_user.id','=','cmc_promotion_coupon.id')
            ->where('cmc_promotion_coupon.id',$data)
            ->where('cmc_promotion_coupon_user.uid',$memberId)
            ->where('cmc_promotion_coupon_user.gid',$gid)
            ->where('cmc_promotion_coupon_user.status',0)
            ->get(['cmc_promotion_coupon.id','cmc_promotion_coupon.title','cmc_promotion_coupon.coupon_price','cmc_promotion_coupon.sill'
                ,'cmc_promotion_coupon_type.type','cmc_promotion_coupon.created_at','cmc_promotion_coupon.coupon_time'])->toArray();
    }
}
